<script>
  window.onload = function () {
    // ========================= masonry =========================
    var grid = document.querySelector('.pgrid');
    var msnry = new Masonry(grid, {
      itemSelector: '.pgrid-item',
      columnWidth: '.pgrid-sizer',
      percentPosition: true,
    });
    imagesLoaded(grid).on('progress', function () {
      msnry.layout();
    });
    
    enquire.register("screen and (max-width:769px)", {
      match: function () {
        document.querySelectorAll('.pgrid-item').forEach(function (elem) {
          elem.classList.add('full');
          elem.classList.remove('half');
        });
        document.querySelectorAll('.pgrid-sizer').forEach(function (elem) {
          elem.classList.add('full');
          elem.classList.remove('half');
        });
      },
      unmatch: function () {
        document.querySelectorAll('.pgrid-item').forEach(function (elem) {
          elem.classList.add('half');
          elem.classList.remove('full');
        });
        document.querySelectorAll('.pgrid-sizer').forEach(function (elem) {
          elem.classList.add('half');
          elem.classList.remove('full');
        });

        var navCollapseBtn = document.querySelector('.navbar__burger');
        var navCollapse = document.getElementsByClassName('navbarm__collapse')[0];
        if (navCollapse) {
          navCollapse.setAttribute('data-open', false);
          navCollapse.style.maxHeight = 0;
          navCollapseBtn.classList.remove('is-active');
        }
      },
    });
    // ===========================================================
  }
</script>